package com.cykj.admin.service.impl;

import com.cykj.admin.mapper.AuditRecordMapper;
import com.cykj.admin.service.IAuditRecordService;
import com.cykj.admin.vo.AuditRecordVO;
import com.cykj.common.dto.ResponseDTO;
import com.cykj.common.entity.RecruitInfoDO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject:@BelonqsPackage:com.cykj.admin.service.impl
 * @Author:jiangna
 * @CreateTime:2025-08-25 09:41
 */
@Service
public class AuditRecordServiceImpl implements IAuditRecordService {
    @Autowired
    private AuditRecordMapper auditRecordMapper;

    /**
    * @Description: 获取所有企业的招聘记录 / 有条件查询
    * @Param: [auditRecordVO]
    * @return: com.cykj.common.dto.ResponseDTO
    */
    @Override
    public ResponseDTO selectAllAuditRecord(AuditRecordVO auditRecordVO) {
        PageInfo<RecruitInfoDO> page;
        //开启分页
        PageHelper.startPage(auditRecordVO.getCurrentPage(), auditRecordVO.getPageSize());
        List<RecruitInfoDO> recruitInfoList = auditRecordMapper.selectAllAuditRecord(auditRecordVO);
        System.out.println("list: " + recruitInfoList);
        page = new PageInfo<>(recruitInfoList);
        if (page.getTotal() < page.getPageSize() && recruitInfoList.size() == 0 && page.getTotal() > 0) {
            auditRecordVO.setCurrentPage(1);
            PageHelper.startPage(auditRecordVO.getCurrentPage(), auditRecordVO.getPageSize());
            List<RecruitInfoDO> recruitInfoList2 = auditRecordMapper.selectAllAuditRecord(auditRecordVO);
            page = new PageInfo<>(recruitInfoList2);
        }
        return ResponseDTO.success(page);
    }

    /**
    * @Description: 审核企业招聘信息（通过/不通过
    * @Param: [auditRecordVO]
    * @return: com.cykj.common.dto.ResponseDTO
    */
    @Override
    public ResponseDTO checkAuditRecord(AuditRecordVO auditRecordVO) {
        int rows = auditRecordMapper.checkAuditRecord(auditRecordVO);
        if (rows > 0) {
            return ResponseDTO.success(rows);
        }
        return ResponseDTO.error("审核失败");
    }

    /**
    * @Description: 按时间范围统计已发布招聘信息的浏览量排行
    * @Param: [rangeType]
    * @return: com.cykj.common.dto.ResponseDTO
    */
    @Override
    public ResponseDTO selectRecruitsByVisitCount(String rangeType) {
        List<RecruitInfoDO> recruitInfoList = auditRecordMapper.selectRecruitsByVisitCount(rangeType);
        if (recruitInfoList == null){
            return ResponseDTO.success("暂无招聘信息");
        }
        return ResponseDTO.success(recruitInfoList);
    }
}
